<?php
/**
 * ClassName:重量选择器
 * @auditor:leijunxiang
 * @time 2025/4/15 14:18
 */

namespace app\tool\freight;

use app\tool\ToolBase;

class WeightSelector extends ToolBase
{
    /**
     * (选择重量)开始处理(重量数组,当前重量)
     */
    public function startHandle($weightArr, $currentWeight)
    {
        $data = 0;
        if (empty($weightArr) || empty($currentWeight)) {
            return $data;
        }
        //重量数组从小到大排列
        sort($weightArr);
        foreach ($weightArr as $weight) {
            if ($weight <= $currentWeight) {
                $data = $weight;
            }
        }
        if ($data == 0) {
            //如果没有找到符合的,则用最小体重的
            $data = $weightArr[0];
        }
        return $data;
    }

}